package com.yang.zngcxyxkjs.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yang.zngcxyxkjs.mapper.AdminMapper;
import com.yang.zngcxyxkjs.mapper.NoticeMapper;
import com.yang.zngcxyxkjs.pojo.Competition;
import com.yang.zngcxyxkjs.pojo.Notice;
import com.yang.zngcxyxkjs.pojo.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class NoticeController {

    @Autowired(required = false)
    private AdminMapper adminMapper;

    @Autowired
    private NoticeMapper noticeMapper;

    @RequestMapping("/showNotices")
    public String showNotice(@RequestParam(defaultValue = "1") Integer currentPageNum, Model model, HttpSession session){

        Student stu = (Student)session.getAttribute("stu");
        model.addAttribute("stu",stu);
        PageHelper.startPage(currentPageNum,5);
        List<Notice> list = adminMapper.selectAllNotice();
        PageInfo<Notice> pageInfo = new PageInfo<>(list);

        model.addAttribute("pageInfo",pageInfo);
        return "student/studentNoticeList.html";
    }

    @RequestMapping("/getNoticeById")
    public String getNoticeById(Integer id,Model model,HttpSession session){
        Notice notice = noticeMapper.selectNoticeById(id);
        model.addAttribute(notice);

        Student stu = (Student)session.getAttribute("stu");
        model.addAttribute("stu",stu);

        return "student/studentGetNoticeById.html";
    }


}
